package cn.hbu.zlfw.exchange.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.hbu.zlfw.common.base.dao.impl.BaseDaoImpl;
import cn.hbu.zlfw.common.util.PageModel;
import cn.hbu.zlfw.exchange.dao.PosterDao;
import cn.hbu.zlfw.exchange.entity.Poster;
/**
 * 
 * @ClassName: PosterDaoImpl 
 * @Description: 留言板主贴dao接口实现
 * @author 王鹏伟<1223443289@qq.com>
 * @date 2017年12月19日 下午9:45:09 
 * @vsersion:v1.0
 */
@Repository("posterDao")
public class PosterDaoImpl  extends BaseDaoImpl<Poster, String> implements PosterDao{
	
	/*
	 * (non-Javadoc)
	 * @see cn.hbu.zlfw.exchange.dao.PosterDao#listPostToPatent(java.lang.String)
	 */
	@Override
	public PageModel<Poster> listPostToPatent(PageModel<Poster> pageModel,String patentId,String title) {
		Map<String,Object> params = new HashMap<String, Object>();
		params.put("id", patentId);
		StringBuffer sbfhql = new StringBuffer();
		StringBuffer sbfhqlCount = new StringBuffer();
		sbfhql.append("from Poster ps inner join fetch ps.patent pt where pt.id=:id ");
		sbfhqlCount.append("select count(*) from Poster ps inner join ps.patent pt where pt.id=:id ");
		if(null != title && "" != title) {
			sbfhql.append("and ps.title like :title ");
			sbfhqlCount.append("and ps.title like :title ");
			params.put("title", "%"+title+"%");
		}
		sbfhql.append(" order by ps.updateTime desc");
		return this.findListByParams(sbfhql.toString(), sbfhqlCount.toString(), params, pageModel);
	}

}
